/**
 * 
 */
package com.base.myproject.client.busi.b2c.b2cgcodeattr;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BaseStoreEvent;
import com.base.myproject.client.busi.BaseStoreListener;
import com.base.myproject.client.busi.JDBCModelData;
import com.base.myproject.client.busi.BaseStoreEvent.EventType;
import com.base.myproject.client.jdbc.StoreInfo;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.form.LabelField;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Widget;

/**
 * 详细的描述，对于用户指定了b2cgcodeattrg,将其显示
 * @author zgw
 *2009-7-22 上午10:28:50
 * javazgw@gmail.com
 */
public class DetailDesc implements B2cGcodeAttr{
	 String b2cgcodeid = null;
	boolean isactive=false;
	LayoutContainer layoutcontainer = new LayoutContainer();
		public String getB2cgcodeid() {
			return b2cgcodeid;
		}

		public void setB2cgcodeid(String b2cgcodeid) {
			this.b2cgcodeid = b2cgcodeid;
		}

	@Override
	public String getName() {
		
		return "描述";
	}

	@Override
	public Object getValue() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Widget getWidget() {
		// TODO Auto-generated method stub
		return layoutcontainer;
	}

	@Override
	public void setName(String name) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setValue(Object value) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setWidget(Widget w) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isavtive() {
		// TODO Auto-generated method stub
		return isactive;
	}

	@Override
	public void setActive(boolean b) {
		// TODO Auto-generated method stub
		
		if(!isactive && b)
		{
			layoutcontainer.add(CreateAttr());
			
			layoutcontainer.layout();
			
		}
		isactive = b;
	}
	
	LayoutContainer CreateAttr(){
		LayoutContainer layoutc = new LayoutContainer();
		
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");

		type.addField("gcode");
		type.addField("b2cgcode");
		type.addField("attrcode");
		type.addField("attrname");
		type.addField("attrvalue");
		StoreInfo info = new StoreInfo();

		info.setTablename("b2cgcodeattrg");
		//info.setKeyname(new String[]{"b2cgcode"});
		info.setSql("select * from b2cgcodeattrg where b2cgcode='"+b2cgcodeid+"'");
//		info.setParent(store);// 关联主表
//		info.setAutoinccolumn("idx"); // 自增字段，如果子表一定需要
//		info.setLinkparentcolumns(new String[] { "ccode" }); // 关联主表字段
		final BaseStore<JDBCModelData> b2cgcodeattrg = new BaseStore<JDBCModelData>(type, info);
		
		final ContentPanel bfp = new ContentPanel();
		//b2cgcodeattrg
		TableLayout tl = new TableLayout(2);
		TableData td = new TableData();
		td.setColspan(1);
		td.setRowspan(1);
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		bfp.setLayout(tl);
		b2cgcodeattrg.addBaseStoreListener(EventType.LOAD_COMPLETE, new BaseStoreListener(){

			@Override
			public void BaseStoreEventHandle(BaseStoreEvent evt) {
				
				for(int i=0;i<b2cgcodeattrg.getCount();i++)
				{
					
					LabelField attrname = new LabelField();
					LabelField attrvalue = new LabelField();
//					System.out.println("00000000="+b2cgcodeattrg.getValue(i, "attrname").toString());
//					System.out.println("22222222="+b2cgcodeattrg.getValue(i, "attrvalue").toString());
					attrname.setText(b2cgcodeattrg.getValue(i, "attrname").toString()+":");
					Object value = b2cgcodeattrg.getValue(i, "attrvalue");
					attrvalue.setText(value==null?"":value.toString());
				
					
					bfp.add(attrname);
					bfp.add(attrvalue);
				//	bfp.add(new Button("i="+i));
				}
				bfp.layout();
			}

			@Override
			public void onBrowserEvent(Event event) {
				// TODO Auto-generated method stub
				
			}
		});
		
//		LabelField attrname = new LabelField();
////		TextField attrname = new TextField();
//		attrname.setName("attrname");
//
//		attrname.setFieldLabel("attrname");
		bfp.setFrame(false);
		bfp.setHeaderVisible(false);
//		bfp.add(attrname);
		
		layoutc.add(bfp);
//		bfp.inited();
	return layoutc;	
	}

}
